// const { ethers } = require("hardhat");


async function main() {
  // 获取签名账户
  const [deployer] = await ethers.getSigners();
  console.log("Deployer address:", deployer.address);

  let receiver = "0xe2CCA88aE9cE333cbbfD418771705632B9C88888";
  console.log("Receiver address:", receiver);

  // 获取已经部署的 MTKcoin 合约地址（假设已经知道）
  const tokenAddress = "0x1377Ce7BadadB01a2D06Dc41f31e8B57d9882888";  // 替换为实际部署的合约地址
  
  // 获取 MyToken 合约的实例
  const MTKcoin = await ethers.getContractFactory("MTKcoin");
  const token = MTKcoin.attach(tokenAddress);

  // 查询部署者的代币余额
  let balance = await token.balanceOf(deployer.address);
  console.log("Deployer's balance:", ethers.utils.formatUnits(balance, 18));

  // 查询接收者的代币余额
  balance = await token.balanceOf(receiver);
  console.log("Receiver's balance:", ethers.utils.formatUnits(balance, 18));

  // 转账 10 个代币给接收者
  const amount = ethers.utils.parseUnits("10", 18);
  console.log(`Transferring 10 tokens from ${deployer.address} to ${receiver}...`);
  
  const tx = await token.transfer(receiver, amount);
  await tx.wait();  // 等待交易确认
  console.log(`Transfer completed!`);

  // 查询转账后的余额
  balance = await token.balanceOf(deployer.address);
  console.log("Deployer's new balance:", ethers.utils.formatUnits(balance, 18));

  balance = await token.balanceOf(receiver);
  console.log("Receiver's new balance:", ethers.utils.formatUnits(balance, 18));
}

// 调用 main 函数并捕获错误
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
